﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.IO;

namespace ModernWSPView.Classes
{
    public static class DropManager
    {
        public static FileInfo GetDroppedFileInfo(IDataObject data)
        {
            FileInfo result = null;

            string filename = GetDroppedFilename(data);
            if (!string.IsNullOrEmpty(filename))
            {
                if (File.Exists(filename))
                {
                    result = new FileInfo(filename);
                }
            }

            return result;
        }

        public static string GetDroppedFilename(IDataObject data)
        {
            string result = string.Empty;

            string[] buffer = GetDroppedFilenames(data);

            if ((buffer != null) && (buffer.Count() == 1))
            {
                result = buffer[0];
            }

            return result;
        }

        public static string[] GetDroppedFilenames(IDataObject data)
        {
            string[] result = null;

            if (data.GetDataPresent(DataFormats.FileDrop, true) == true)
            {
                result = (string[])data.GetData(DataFormats.FileDrop, true);
            }

            return result;
        }
    }
}
